import http from '../../utils/request/request'
const URL = '/file/management';

// type:deleted(总删除记录) or self/deleted（自己的删除记录) or self(自己上传的) or null(所有上传的)
export function getAllInfoByPage(page = 1, size = 10, type = "") {
    return http({
        url: `${URL}/${type ? type + "/" : ""}${size}/${page}`,
        method: 'get'
    })
}

export function addInfo(data) {
    return http({
        url: `${URL}/upload`,
        method: 'post',
        data,
    })
}

// real:true(在删除历史记录中删除) or false(普通删除)
export function delInfoById(id, real = false) {
    let url = URL
    if (real) {
        url += `/real/${id}`
    } else {
        url += `/${id}`
    }
    return http({
        url,
        method: 'delete'
    })
}

// real:true(在删除历史记录中批量删除) or false(普通批量删除)
export function delInfoByIds(ids, real = false) {

    let url = URL + '/batch'
    if (real) {
        url += `/real`
    }
    return http({
        url,
        method: 'delete',
        data: ids
    })
}

export function recoverInfoById(id) {
    return http({
        url: `${URL}/recover/${id}`,
        method: 'put'
    })
}

export function recoverInfoByIds(ids) {
    return http({
        url: `${URL}/recover/batch`,
        method: 'put',
        data: ids
    })
}

export function renameInfoById(id, fileName) {
    return http({
        url: `${URL}/rename/${id}?fileName=${fileName}`,
        method: 'put',
    })
}
